import { nextTick  } from 'vue'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import router from '@/router'
import store from '@/store'

export default {
	//刷新标签
	refresh() {
		NProgress.start()
		const route = router.currentRoute.value
		store.commit("removeKeepLive", this.routemodulename(route))
		store.commit("setRouteShow", false)
		nextTick(() => {
			store.commit("pushKeepLive", this.routemodulename(route))
			store.commit("setRouteShow", true)
			NProgress.done()
			//setTimeout(() => {
				
			//}, 2000);
		})
	},
	//关闭标签
	close(tag) {
		const route = tag || router.currentRoute.value
		store.commit("removeViewTags", route)
		store.commit("removeIframeList", route)
		store.commit("removeKeepLive", this.routemodulename(route))
		const tagList = store.state.viewTags.viewTags
		const latestView = tagList.slice(-1)[0]
		if (latestView) {
			router.push(latestView)
		} else {
			router.push('/')
		}
	},
	//关闭标签后处理
	closeNext(next) {
		const route = router.currentRoute.value
		store.commit("removeViewTags", route)
		store.commit("removeIframeList", route)
		store.commit("removeKeepLive", this.routemodulename(route))
		if(next){
			const tagList = store.state.viewTags.viewTags
			next(tagList)
		}
	},
	//关闭其他
	closeOther() {
		const route = router.currentRoute.value
		const tagList = [...store.state.viewTags.viewTags]
		tagList.forEach(tag => {
			if(tag.meta&&tag.meta.affix || route.fullPath==tag.fullPath){
				return true
			}else{
				this.close(tag)
			}
		})
	},
	//设置标题
	setTitle(title){
		store.commit("updateViewTagsTitle", title)
	},
	//去掉单据列表的缓存
	refreshDocumentInfo() {
		store.commit("removeKeepLive", "单据信息列表")
	},
	
	routemodulename(route){
		if(route.name=="documentDetail"){
			return "documentDetail";
		}else if(route.name=="documentPrepare"){
			return "documentDetail";
		}else if(route.name=="messageCenter"){
			return "消息中心";
		}else if(route.name=="toAssetList"){
			return "资产台账";
		}else if(route.name=="toAssetLog"){
			return "资产履历信息";
		}else if(route.name=="toAssetLogByGroup"){
			return "资产履历查询";
		}else if(route.name=="checkDocumentDetail"){
			return "盘点单";
		}else if(route.name=="checkDocumentPrepare"){
			return "盘点单";
		}else if(route.name=="newCheckDocumentPrepare"){
			return "盘点单编辑";
		}else if(route.name=="checkDetailPrepare"){
			return "盘点单明细";
		}else if(route.name=="checkDoPrepare"){
			return "盘点处理";
		}else if(route.name=="myPending"){
			return "审批中心";
		}else if(route.fullPath.indexOf("/assetDocument/")==0){
			return "单据信息列表";
		}else if(route.fullPath.indexOf("/index/permision/")==0){
			return "单据信息列表";
		}else if(route.fullPath.indexOf("/index/tempLeave/")==0){
			return "单据信息列表";
		}			

		return route.name;
	},
	tagmodulename(tag){
		if(tag.name=="documentDetail"){
			return "documentDetail";
		}else if(tag.name=="documentPrepare"){
			return "documentDetail";
		}else if(tag.name=="messageCenter"){
			return "消息中心";
		}else if(tag.name=="toAssetList"){
			return "资产台账";
		}else if(tag.name=="toAssetLog"){
			return "资产履历信息";
		}else if(tag.name=="toAssetLogByGroup"){
			return "资产履历查询";
		}else if(tag.name=="checkDocumentDetail"){
			return "盘点单";
		}else if(tag.name=="checkDocumentPrepare"){
			return "盘点单";
		}else if(tag.name=="newCheckDocumentPrepare"){
			return "盘点单编辑";
		}else if(tag.name=="checkDetailPrepare"){
			return "盘点单明细";
		}else if(tag.name=="checkDoPrepare"){
			return "盘点处理";
		}else if(tag.name=="myPending"){
			return "审批中心";
		}else if(tag.fullPath.indexOf("/assetDocument/")==0){
			return "单据信息列表";
		}else if(tag.fullPath.indexOf("/index/permision/")==0){
			return "单据信息列表";
		}else if(tag.fullPath.indexOf("/index/tempLeave/")==0){
			return "单据信息列表";
		}					

		return tag.name;
	}
}
